import settings
import bsddb
import struct
import sys

class Database:
    def __init__(self):
        self.webgraph = bsddb.btopen(settings.db_webgraph,'c')
        self.hashurl = bsddb.btopen(settings.db_hashurl,'c')
        self.hashurl['totalurl'] = '0'
        self.totalurl = 0

    def addurl(self,url):
        if not self.hashurl.has_key(url) :
            self.totalurl = id = self.totalurl + 1
            self.hashurl['totalurl'] = str(id)
            self.hashurl[str(url)] = str(id)
            self.hashurl.sync()
            return True
        else:
            return False

    #def makenode(self,src,dest):


    def close(self):
        self.hashurl.close()
        self.webgraph.close()
